package com.zx.server.util;

/**
 * author:lijiancheng@qmrkj
 * Date:2019-01-22
 * Time:11:35
 * Description: 响应分页通用对象。
 */
public class ResponsePageUtil {

    /**
     * 分页大小
     */
    private Integer pageSize;
    /**
     * 总页数
     */
    private Integer totalPage;
    /**
     * 当前页码
     */
    private Integer pageNum;
    /**
     * 总数
     */
    private Integer total;
    /**
     * 开始row记录数
     */
    private Integer startRow;
    /**
     * 结束row记录数
     */
    private Integer endRow;
    /**
     * 是否为第一页
     */
    private boolean fristPage;
    /**
     * 是否为最后一页
     */
    private boolean lastPage;
    /**
     * 是否有下一页
     */
    private boolean hasNextPage;
    /**
     * 是否有上一页
     */
    private boolean hasPreviousPage;
    /**
     * 下一页页码
     */
    private Integer nextPage;
    /**
     * 上一页页码
     */
    private Integer prePage;

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getTotalPage() {
        totalPage = getTotal() / getPageSize();
        return (total % pageSize == 0) ? totalPage : totalPage + 1;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getTotal() {
        return total;
    }

    public Integer getStartRow() {
        return (pageNum - 1) * pageSize;
    }

    public Integer getEndRow() {
        return isLastPage() ? total : pageNum * pageSize;
    }

    public boolean isFristPage() {
        return (pageNum == 1) ? true : false;
    }

    public boolean isLastPage() {
        return (pageNum == getTotalPage()) ? true : false;
    }

    public boolean isHasNextPage() {
        return isLastPage() ? false : true;
    }

    public boolean isHasPreviousPage() {
        return isFristPage() ? false : true;
    }

    public Integer getNextPage() {
        return pageNum + 1;
    }

    public Integer getPrePage() {
        return pageNum - 1;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public void setStartRow(Integer startRow) {
        this.startRow = startRow;
    }

    public void setEndRow(Integer endRow) {
        this.endRow = endRow;
    }

    public void setFristPage(boolean fristPage) {
        this.fristPage = fristPage;
    }

    public void setLastPage(boolean lastPage) {
        this.lastPage = lastPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public void setHasPreviousPage(boolean hasPreviousPage) {
        this.hasPreviousPage = hasPreviousPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public ResponsePageUtil(Integer pageSize, Integer pageNum, Integer total) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.total = total;
    }

    @Override
    public String toString() {
        return "ResponsePageUtil{" +
                "pageSize=" + getPageSize() +
                ", totalPage=" + getTotalPage() +
                ", pageNum=" + getPageNum() +
                ", total=" + getTotal() +
                ", startRow=" + getStartRow() +
                ", endRow=" + getEndRow() +
                ", fristPage=" + isFristPage() +
                ", lastPage=" + isLastPage() +
                ", hasNextPage=" + isHasNextPage() +
                ", hasPreviousPage=" + isHasPreviousPage() +
                ", nextPage=" + getNextPage() +
                ", prePage=" + getPrePage() +
                '}';
    }
}

